<?php 
class MeasureModel extends Model
{
	/**
	 * 查询身型数据的字段
	 * @return array 
	 */
	public static function user_measure_field()
	{
		$user_measure_field_db = D('user_measure_field');
		$user_measure_field = $user_measure_field_db -> select();
		return $user_measure_field;
	}

	/**
	 * 返回用户身型字段从特定到现在的身型增减数据
	 * @return float 
	 */
	public static function user_measure_val_edit($size_edit_measure, $field)
	{
        if(!$size_edit_measure || !$field) return 0;
        $return_val = 0;
        foreach($size_edit_measure as $key=>$val){
        	$data = unserialize($val['data']);
			foreach($data as $k=>$v){
				if($k == $field){
                    $return_val += $v;
				}
			}
        }
		return $return_val;
	}
	
	/**
	 * 返回用户身型
	 * @return float 
	 */	
	public static function get_measure_info($mid){
	    $measure_infos = D('user_measure')->where(array('id'=>$mid))->find();
		return $measure_infos;
	}
    public static function edit_measure_info($mid,$post){
        $measure_id= D('user_measure')->where(array('id'=>$mid))->save($post);
        return  $measure_id;
    }
	
	/**
	 * 查询身型数据
	 * @return array 
	 */
	public static function get_measure_one($post)
	{
		$filter = array(
			'user_id' => isset($post['user_id']) ? intval($post['user_id']) : null,
            'address_id' => isset($post['address_id']) ? intval($post['address_id']) : null,
            'id' => isset($post['id']) ? intval($post['id']) : null,
		);

		foreach ($filter as $key => $val){
			if(is_null($val)){
				unset($filter[$key]);
			}
		}

		$user_measure_db = D('user_measure');
		$measure = $user_measure_db->where($filter)->find();
		return $measure;
	}
}